#pragma once 

#include "InetAddress.h"
#include "SocketOpt.h"
#include "Event.h"
#include "EventLoop.h"


namespace tmms
{
    namespace  network
    {
        using AcceptCallback = std::function<void(int sock,const InetAddress &addr)>;
        class Acceptor:public Event//的核心职责是​​处理新连接建立事件听套接字（ServerSocket）只需关注​​连接建立请求​​（EPOLLIN），无需处理数据发送（EPOLLOUT）。​​
        {
        public:
            Acceptor(EventLoop * loop,const InetAddress &addr);
            ~Acceptor();

            void SetAcceptCallback(const AcceptCallback &cb);
            void SetAcceptCallback(const AcceptCallback &&cb);

            void Start();
            void Stop();
            void OnRead() override; //
            void OnError(const std::string &msg) override;
            void OnClose() override;
            void Open();
        private:
            //void Open();
            InetAddress addr_;
            AcceptCallback accept_cb_;
            //int fd_;
            SocketOpt* socket_opt_ {nullptr};     
        };
    }
}
